package nil.ed.simulator.request.ui.jfx.event;

import javafx.scene.control.Alert;
import nil.ed.simulator.request.enums.events.EventType;
import nil.ed.simulator.request.event.Event;
import nil.ed.simulator.request.event.bus.EventListener;

/**
 * @author lidelin.
 */
public class ExportCookieTaskResultListener implements EventListener {
    @Override
    public void onEvent(Event event) {
        boolean success = event.getEventType() == EventType.FILE_EXPORT_SUCCESS;
        Alert.AlertType alertType = success ? Alert.AlertType.INFORMATION : Alert.AlertType.CONFIRMATION;
        String title = success ? "导出成功" : "导出失败";
        String content = success ? "导出成功, 文件位置: " + event.getData() : "导出失败";
        Alert alert = new Alert(alertType);
        alert.setTitle(title);
        alert.setContentText(content);
        alert.show();
    }

    @Override
    public boolean isSupport(Event event) {
        return event.getEventType() == EventType.FILE_EXPORT_SUCCESS || event.getEventType() == EventType.FILE_EXPORT_FAILED;
    }
}
